using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace FCalendar
{
    public partial class FormBox : Form
    {
        public FormBox()
        {
            InitializeComponent();
        }

        public string boxText = "";

        private Point offsetPoint;
        private bool buttonDown = false;

        private void FormBox_MouseDown(object sender, MouseEventArgs e)
        {
            offsetPoint.X = Left - MousePosition.X;
            offsetPoint.Y = Top - MousePosition.Y;
            buttonDown = true;
        }

        private void FormBox_MouseUp(object sender, MouseEventArgs e)
        {
            buttonDown = false;
        }

        private void FormBox_MouseMove(object sender, MouseEventArgs e)
        {
            if (buttonDown)
            {
                this.Location = new Point(MousePosition.X + offsetPoint.X, MousePosition.Y + offsetPoint.Y);
            }
        }

        private void FormBox_Load(object sender, EventArgs e)
        {
            ContextMenu = Program.mainForm.ContextMenu;
            TopMost = Program.foption.checkBox1.Checked;
            Opacity = (double)Program.foption.trackBar1.Value / 100;
        }

        private void mainFormShowToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Program.mainForm.ShowCalendarForm();
        }

        private void hideToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Hide();
        }

        private void optionToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Program.foption.Show();
        }

        private void FormBox_VisibleChanged(object sender, EventArgs e)
        {
            if (Visible == true)
                Program.mainForm.boxToolStripMenuItem.Checked = true;
            else
                Program.mainForm.boxToolStripMenuItem.Checked = false;
        }

        private void editableToolStripMenuItem_Click(object sender, EventArgs e)
        {
            editableToolStripMenuItem.Checked = !editableToolStripMenuItem.Checked;
            farsiCalendarControl1.Enabled = editableToolStripMenuItem.Checked;
            if (editableToolStripMenuItem.Checked)
            {
                // Fade in by timer
                mouseEnter = true;
                timer1.Enabled = true;
            }
            else
            {
                // Fade out by timer
                mouseEnter = false;
                timer1.Enabled = true;
            }
        }

        private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            About af = new About();
            af.ShowDialog(this);
        }

        private void todayToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Program.IsToday = !Program.IsToday;
            if (Program.IsToday)
                farsiCalendarControl1.SelectedGeoValue = DateTime.Today;
        }

        private bool mouseEnter = false;

        private void FormBox_MouseEnter(object sender, EventArgs e)
        {
            mouseEnter = true;
            timer1.Enabled = true;
        }

        private void FormBox_MouseLeave(object sender, EventArgs e)
        {
            mouseEnter = false;
            timer1.Enabled = true;
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (mouseEnter)
            {
                Opacity += 0.01D;
                if (Opacity >= 1D)
                {
                    Opacity = 1D;
                    timer1.Enabled = false;
                }
            }
            else
            {
                Opacity -= 0.01D;
                double o = (double)Program.foption.trackBar1.Value / 100;
                if (Opacity <= o)
                {
                    Opacity = o;
                    timer1.Enabled = false;
                }
            }
        }

        private void farsiCalendarControl1_SelectDay(object sender)
        {
            Program.IsToday = false;
        }

    }
}